package com.song.article;

import com.song.api.config.RabbitMQDelayConfig;
import com.song.article.service.ArticleService;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RabbitMQDelayConsumer {


    @Autowired
    private ArticleService articleService;
    /**
     * 监听消息队列
     *
     * @param payload 消息内容
     * @param message 消息对象
     */
    @RabbitListener(queues = {RabbitMQDelayConfig.QUEUE_DELAY})
    public void watchQueue(String payload, Message message) {

        String routingKey = message.getMessageProperties().getReceivedRoutingKey();
        System.out.println(routingKey);

        if (routingKey.equalsIgnoreCase("publish.delay.display")) {
            // 消费者接收到定时发布的延迟消息，修改当前状态为`即时发布`
            String articleId = payload;
            articleService.updateArticleToPublish(articleId);
        }

    }

}

